﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;

namespace GraphDrawer
{
	public partial class NewEdgePopUp : UserControl
	{
        public event RoutedEventHandler Closed;
        public event RoutedEventHandler OK;

        public NewEdgePopUp()
		{
			// Required to initialize variables
			InitializeComponent();
            this.KeyDown += new KeyEventHandler(NewEdgePopUp_KeyDown);
            //MainPopupGrid.Height = App.Current.
            Closed += new RoutedEventHandler(NewNodePopUp_Closed);
            OK += new RoutedEventHandler(NewNodePopUp_OK);
		}

        void NewEdgePopUp_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                OK.Invoke(this, new RoutedEventArgs());
            }
            if (e.Key == Key.Escape)
            { 
                Closed.Invoke(this, new RoutedEventArgs());   
            }
        }

        public double Probability
        {
            get 
            {
                if (String.IsNullOrEmpty(Name.Text))
                {
                    return 0;
                }
                else
                {
                    return Convert.ToDouble(Name.Text);                    
                }
            }
        }

        void NewNodePopUp_OK(object sender, RoutedEventArgs e)
        {
            Visibility = Visibility.Collapsed;            
        }

        void NewNodePopUp_Closed(object sender, RoutedEventArgs e)
        {
            Visibility = Visibility.Collapsed;
        }

        private void CloseBtn_Click(object sender, RoutedEventArgs e)
        {            
            Closed.Invoke(sender, e);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {            
            OK.Invoke(this, e);
        }
	}
}